package com.qf.business.course.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ken.event.action.apply.producer.EventTemplate;
import com.qf.business.course.dao.CourseDao;
import com.qf.business.course.service.CourseService;
import com.qf.commons.web.aspect.annotation.GetUser;
import com.qf.commons.web.aspect.utils.UserUtils;
import com.qf.data.course.entity.Course;
import com.qf.data.user.entity.Teacher;
import org.springframework.stereotype.Service;

/**
 * 课程信息表(Course)表服务实现类
 *
 * @author makejava
 * @since 2022-11-29 16:34:52
 */
@Service("courseService")
public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements CourseService {


    /**
     * 保存课程
     * @param entity 实体对象
     * @return
     */
    @Override
    @GetUser
    public boolean save(Course entity) {

        //对entity做一些修改
        Teacher teacher = UserUtils.getUser(Teacher.class);
        entity.setTid(teacher.getId());

        //保存到数据库
        boolean save = super.save(entity);

        if(save) {
            EventTemplate.sendQuickly("course_insert", entity);
        }
        return save;
    }

    @Override
    public Course queryCourseById(Integer cid) {
        return getBaseMapper().queryCourseById(cid);
    }
}

